#include <stdio.h>
#define N 13

struct person {
    int number;
    int nextp;
} link[N + 1];

int main() {
    int i, count, h;

    for (i = 1; i <= N; i++) {
        link[i].number = i;
        if (i == N)
            link[i].nextp = 1;
        else
            link[i].nextp = i + 1;
    }

    printf("Sequence of persons leaving the circle:\n");
    count = 0;
    h = N;
    while (count < N - 1) {
        for (i = 1; i <= 3; i++) {
            h = link[h].nextp;
            while (link[h].number == 0)
                h = link[h].nextp;
        }
        printf("%4d", link[h].number);
        link[h].number = 0;
        count++;
    }

    printf("\nThe last person remaining is: ");
    for (i = 1; i <= N; i++) {
        if (link[i].number != 0) {
            printf("%4d", link[i].number);
            break;
        }
    }
    printf("\n");
    return 0;
}